<template>
  <view class="loginMain cflex flex_y_center flex_x_center">
    <view class="imgBox">
      <image src="https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/13/e977d7178c7941a1b7284de2cb1f5624.png" mode="widthFix"></image>
    </view>
    <view class="flex_h_25" v-if="indexFlag"></view>
    <view class="rflex flex_x_center flex_y_center" style="color: red;font-size: 3.5vw" v-if="indexFlag">您还没有登录，请登录后查看该功能</view>
    <view class="flex_h_50"></view>
    <uv-button  class="loginBtn" type="primary" color="#2D4C98" shape="circle" open-type="getPhoneNumber" @getphonenumber="getphonenumber" v-if="radioVal == 1">一键登录</uv-button>
    <uv-button  class="loginBtn" type="primary" color="#2D4C98" @click="btnClick" shape="circle"  v-else>一键登录</uv-button>
    <view class="flex_h_15"></view>
    <uv-button  class="loginBtn" type="info" plain shape="circle" @click="handleCancel">取 消</uv-button>
    <div class="lastBox">
      <uv-checkbox-group shape="circle" v-model="radioVal" style="width: 100%">
        <view class="rflex flex_1 flex_y_center flex_x_center" style="width: 100%">
          <uv-checkbox  name="1">
            <view class="rflex flex_1 flex_y_center flex_x_center">
              <view>我已阅读并同意</view>
              <view class="checkbox_text_text" @click.stop="gogogo('https://www.sibossccc.com/h5/yhxy.html')">《用户协议》</view>
              <view class="checkbox_text_text" @click.stop="gogogo('https://www.sibossccc.com/h5/yszc.html')">《隐私政策》</view>
            </view>
          </uv-checkbox >
        </view>
      </uv-checkbox-group>
    </div>
  </view>
</template>

<script>
import WxLoginApi from "@/api/wxLogin/wxLogin";
import {setToken, setUserInfoId} from "@/utils/auth";

export default {
  data() {
    return {
      indexFlag: false,
      radioVal: null,
      form:{}
    };
  },
  onLoad(options) {
    this.indexFlag = options.showFlag != 'canShow';
  },
  methods:{
    btnClick() {
      console.log(this.radioVal);
      uni.showToast({
        title: '请先勾选我已阅读并同意隐私政策和用户协议',
        icon: 'none'
      });
    },
    gogogo(url) {
      uni.navigateTo( {
        url: '/page_login/webLooks?url=' + url,
      })
    },
    handleCancel() {
      uni.switchTab({
        url: '/pages/index'
      })
    },
    getphonenumber(e) {
      const that = this;
      if (e.errMsg == 'getPhoneNumber:ok') {
        uni.login({
          provider: 'weixin',
          success: (res) => {
            const data = {
              phoneCode: e.code,
              code: res.code,
              type: 2
            }
            WxLoginApi.wxLogin(data).then(res => {
              setToken(res?.data?.token);
              setUserInfoId(res?.data?.id)
              uni.showToast( {
                title: '登录成功',
                icon: 'success',
                duration: 2000
              })
              setTimeout(() => {
                uni.switchTab({
                  url: '/pages/index'
                })
              }, 1500);
              // that.form  = res?.data;
              // if (that.form.type) {
              //   that.form.type = that.form.type.split(',')
              //   that.form.type.forEach(item => {
              //     switch (item) {
              //       case '4':
              //         that.userTypeStr = '销售';
              //         break;
              //       case '7':
              //         that.userTypeStr = '采购';
              //         break;
              //     }
              //   })
              // }
            });
          }
        })
      }
    },
  }
}
</script>

<style scoped lang="scss">
.loginMain{
  width: 100vw;
  height: 100vh;
  background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/13/745de3ab4729493ea095365311d84e06.jpg") no-repeat;
  background-size: 100% 100%;
  .imgBox{
    width: 180px;
    height: auto;
  }

  ::v-deep .uv-button{
    width: 90vw !important;
  }
  .lastBox{
    font-size: 3vw;
    position: fixed;
    bottom: 25px;
    .checkbox_text_text{
      color: blue;
    }
  }
}
</style>
